package com.ruibang.glass.quality.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.quality.domain.req.SpecsConfigReq;
import com.ruibang.glass.quality.domain.resp.SemiGlassResp;
import com.ruibang.glass.quality.entity.SpecsConfig;
import com.ruibang.glass.quality.mapper.SpecsConfigMapper;
import com.ruibang.glass.quality.service.SpecsConfigService;
import com.teaming.cloud.framework2.common.pojo.PageRequest;
import com.teaming.cloud.framework2.common.pojo.PageResult;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 半成品检查规格参数配置 服务实现类
 * </p>
 *
 * @author wujie
 * @since 2024-03-12
 */
@Service
public class SpecsConfigServiceImpl extends ServiceImpl<SpecsConfigMapper, SpecsConfig> implements SpecsConfigService {

    @Override
    public void saveInfo(SpecsConfig specsConfig) {
        this.save(specsConfig);
    }

    @Override
    public void updateInfo(SpecsConfig specsConfig) {
        specsConfig.setFlowRangeControlLimit(null);
        //更新文件信息
        this.updateById(specsConfig);
    }

    @Override
    public PageResult<SpecsConfig> queryPage(PageRequest<SpecsConfigReq> pageRequest) {
        final SpecsConfigReq param = pageRequest.getParam();
        final LambdaQueryWrapper<SpecsConfig> lambda = new QueryWrapper<SpecsConfig>().lambda();
        this.buildCondition(lambda,param);
        final IPage<SpecsConfig> page = this.page(new Page<>(pageRequest.getPageNo(), pageRequest.getPageSize()), lambda);
        PageResult<SpecsConfig> pr = new PageResult(page);
        return pr;
    }

    @Override
    public List<SpecsConfig> querySpecsConfig(SpecsConfigReq rippleReq) {
        final LambdaQueryWrapper<SpecsConfig> lambda = new QueryWrapper<SpecsConfig>().lambda();
        this.buildCondition(lambda,rippleReq);
        return this.list(lambda);
    }

    @Override
    public List<SpecsConfig> getSpecsConfigByIds(List<String> specsIds) {
        return baseMapper.getSpecsConfigByIds(specsIds);
    }

    @Override
    public List<SemiGlassResp> getGlassData(String glassId) {
        //return baseMapper.getGlassData(glassId);
        return null;
    }

    /**
     * 构造查询条件
     * @param lambda
     * @param param
     */
    private void buildCondition(LambdaQueryWrapper<SpecsConfig> lambda, SpecsConfigReq param){
        if(null == param) return;
        if(!StringUtils.isEmpty(param.getSpecsId())){
            lambda.eq(SpecsConfig::getSpecsId, param.getSpecsId());
        }
        if(!StringUtils.isEmpty(param.getSpecsName())){
            lambda.like(SpecsConfig::getSpecsName, param.getSpecsName());
        }
        if(!StringUtils.isEmpty(param.getCheckItem())){
            lambda.eq(SpecsConfig::getCheckItem, param.getCheckItem());
        }
        if(!StringUtils.isEmpty(param.getGlassType())){
            lambda.eq(SpecsConfig::getGlassType, param.getGlassType());
        }
        if(!StringUtils.isEmpty(param.getGlassModel())){
            lambda.eq(SpecsConfig::getGlassModel, param.getGlassModel());
        }
        if(!StringUtils.isEmpty(param.getFlowRangeSpecsOperator())){
            lambda.eq(SpecsConfig::getFlowRangeSpecsOperator, param.getFlowRangeSpecsOperator());
        }
        if(!StringUtils.isEmpty(param.getFlowRangeSpecsValue())){
            lambda.eq(SpecsConfig::getFlowRangeSpecsValue, param.getFlowRangeSpecsValue());
        }
        if(!StringUtils.isEmpty(param.getFullRangeSpecsOperator())){
            lambda.eq(SpecsConfig::getFullRangeSpecsOperator, param.getFullRangeSpecsOperator());
        }
        if(!StringUtils.isEmpty(param.getFullRangeSpecsValue())){
            lambda.eq(SpecsConfig::getFullRangeSpecsValue, param.getFullRangeSpecsValue());
        }
        if(!StringUtils.isEmpty(param.getFullWarpingSpecsOperator())){
            lambda.eq(SpecsConfig::getFullWarpingSpecsOperator, param.getFullWarpingSpecsOperator());
        }
        if(!StringUtils.isEmpty(param.getFullWarpingSpecsValue())){
            lambda.eq(SpecsConfig::getFullWarpingSpecsValue, param.getFullWarpingSpecsValue());
        }
        if(!StringUtils.isEmpty(param.getAStripeSpecsOperator())){
            lambda.eq(SpecsConfig::getAStripeSpecsOperator, param.getAStripeSpecsOperator());
        }
        if(!StringUtils.isEmpty(param.getAStripeSpecsValue())){
            lambda.eq(SpecsConfig::getAStripeSpecsValue, param.getAStripeSpecsValue());
        }
        if(!StringUtils.isEmpty(param.getCStripeSpecsOperator())){
            lambda.eq(SpecsConfig::getCStripeSpecsOperator, param.getCStripeSpecsOperator());
        }
        if(!StringUtils.isEmpty(param.getCStripeSpecsValue())){
            lambda.eq(SpecsConfig::getCStripeSpecsValue, param.getCStripeSpecsValue());
        }
        if(!StringUtils.isEmpty(param.getRippleSpecsOperator())){
            lambda.eq(SpecsConfig::getRippleSpecsOperator, param.getRippleSpecsOperator());
        }
        if(!StringUtils.isEmpty(param.getRippleSpecsValue())){
            lambda.eq(SpecsConfig::getRippleSpecsValue, param.getRippleSpecsValue());
        }
        if(!StringUtils.isEmpty(param.getStressSpecsOperator())){
            lambda.eq(SpecsConfig::getStressSpecsOperator, param.getStressSpecsOperator());
        }
        if(!StringUtils.isEmpty(param.getStressSpecsValue())){
            lambda.eq(SpecsConfig::getStressSpecsValue, param.getStressSpecsValue());
        }
        if(!StringUtils.isEmpty(param.getDeflectSpecsOperator())){
            lambda.eq(SpecsConfig::getDeflectSpecsOperator, param.getDeflectSpecsOperator());
        }
        if(!StringUtils.isEmpty(param.getDeflectSpecsValue())){
            lambda.eq(SpecsConfig::getDeflectSpecsValue, param.getDeflectSpecsValue());
        }
        if(!StringUtils.isEmpty(param.getFlowRangeControlLimit())){
            lambda.eq(SpecsConfig::getFlowRangeControlLimit, param.getFlowRangeControlLimit());
        }
        if(!StringUtils.isEmpty(param.getFullRangeControlLimit())){
            lambda.eq(SpecsConfig::getFullRangeControlLimit, param.getFullRangeControlLimit());
        }
        if(!StringUtils.isEmpty(param.getFullWarpingControlLimit())){
            lambda.eq(SpecsConfig::getFullWarpingControlLimit, param.getFullWarpingControlLimit());
        }
        if(!StringUtils.isEmpty(param.getBStripeSpecs())){
            lambda.eq(SpecsConfig::getBStripeSpecs, param.getBStripeSpecs());
        }
        if(!StringUtils.isEmpty(param.getStripeControlLevel())){
            lambda.eq(SpecsConfig::getStripeControlLevel, param.getStripeControlLevel());
        }
        if(!StringUtils.isEmpty(param.getStressControlLimit())){
            lambda.eq(SpecsConfig::getStressControlLimit, param.getStressControlLimit());
        }
        if(!StringUtils.isEmpty(param.getFlowThicknessStandard())){
            lambda.eq(SpecsConfig::getFlowThicknessStandard, param.getFlowThicknessStandard());
        }
        if(!StringUtils.isEmpty(param.getFlowThicknessTolerance())){
            lambda.eq(SpecsConfig::getFlowThicknessTolerance, param.getFlowThicknessTolerance());
        }
        if(!StringUtils.isEmpty(param.getFlowThicknessControlLimitOne())){
            lambda.eq(SpecsConfig::getFlowThicknessControlLimitOne, param.getFlowThicknessControlLimitOne());
        }
        if(!StringUtils.isEmpty(param.getFlowThicknessControlLimitTwo())){
            lambda.eq(SpecsConfig::getFlowThicknessControlLimitTwo, param.getFlowThicknessControlLimitTwo());
        }
        if(!StringUtils.isEmpty(param.getNoFlowThicknessStandard())){
            lambda.eq(SpecsConfig::getNoFlowThicknessStandard, param.getNoFlowThicknessStandard());
        }
        if(!StringUtils.isEmpty(param.getNoFlowThicknessTolerance())){
            lambda.eq(SpecsConfig::getNoFlowThicknessTolerance, param.getNoFlowThicknessTolerance());
        }
        if(!StringUtils.isEmpty(param.getNoFlowThicknessControlLimitOne())){
            lambda.eq(SpecsConfig::getNoFlowThicknessControlLimitOne, param.getNoFlowThicknessControlLimitOne());
        }
        if(!StringUtils.isEmpty(param.getNoFlowThicknessControlLimitTwo())){
            lambda.eq(SpecsConfig::getNoFlowThicknessControlLimitTwo, param.getNoFlowThicknessControlLimitTwo());
        }
        if(!StringUtils.isEmpty(param.getFullThicknessMaxStandard())){
            lambda.eq(SpecsConfig::getFullThicknessMaxStandard, param.getFullThicknessMaxStandard());
        }
        if(!StringUtils.isEmpty(param.getFullThicknessMaxTolerance())){
            lambda.eq(SpecsConfig::getFullThicknessMaxTolerance, param.getFullThicknessMaxTolerance());
        }
        if(!StringUtils.isEmpty(param.getFullThicknessMaxControlLimitOne())){
            lambda.eq(SpecsConfig::getFullThicknessMaxControlLimitOne, param.getFullThicknessMaxControlLimitOne());
        }
        if(!StringUtils.isEmpty(param.getFullThicknessMaxControlLimitTwo())){
            lambda.eq(SpecsConfig::getFullThicknessMaxControlLimitTwo, param.getFullThicknessMaxControlLimitTwo());
        }
        if(!StringUtils.isEmpty(param.getFullThicknessMinStandard())){
            lambda.eq(SpecsConfig::getFullThicknessMinStandard, param.getFullThicknessMinStandard());
        }
        if(!StringUtils.isEmpty(param.getFullThicknessMinTolerance())){
            lambda.eq(SpecsConfig::getFullThicknessMinTolerance, param.getFullThicknessMinTolerance());
        }
        if(!StringUtils.isEmpty(param.getFullThicknessMinControlLimitOne())){
            lambda.eq(SpecsConfig::getFullThicknessMinControlLimitOne, param.getFullThicknessMinControlLimitOne());
        }
        if(!StringUtils.isEmpty(param.getFullThicknessMinControlLimitTwo())){
            lambda.eq(SpecsConfig::getFullThicknessMinControlLimitTwo, param.getFullThicknessMinControlLimitTwo());
        }
        if(!StringUtils.isEmpty(param.getFullThicknessAverageStandard())){
            lambda.eq(SpecsConfig::getFullThicknessAverageStandard, param.getFullThicknessAverageStandard());
        }
        if(!StringUtils.isEmpty(param.getFullThicknessAverageTolerance())){
            lambda.eq(SpecsConfig::getFullThicknessAverageTolerance, param.getFullThicknessAverageTolerance());
        }
        if(!StringUtils.isEmpty(param.getFullThicknessAverageControlLimitOne())){
            lambda.eq(SpecsConfig::getFullThicknessAverageControlLimitOne, param.getFullThicknessAverageControlLimitOne());
        }
        if(!StringUtils.isEmpty(param.getFullThicknessAverageControlLimitTwo())){
            lambda.eq(SpecsConfig::getFullThicknessAverageControlLimitTwo, param.getFullThicknessAverageControlLimitTwo());
        }
        if(!StringUtils.isEmpty(param.getLongSizeStandard())){
            lambda.eq(SpecsConfig::getLongSizeStandard, param.getLongSizeStandard());
        }
        if(!StringUtils.isEmpty(param.getLongSizeTolerance())){
            lambda.eq(SpecsConfig::getLongSizeTolerance, param.getLongSizeTolerance());
        }
        if(!StringUtils.isEmpty(param.getShortSizeStandard())){
            lambda.eq(SpecsConfig::getShortSizeStandard, param.getShortSizeStandard());
        }
        if(!StringUtils.isEmpty(param.getShortSizeTolerance())){
            lambda.eq(SpecsConfig::getShortSizeTolerance, param.getShortSizeTolerance());
        }
        if(!StringUtils.isEmpty(param.getDiagonalSizeStandard())){
            lambda.eq(SpecsConfig::getDiagonalSizeStandard, param.getDiagonalSizeStandard());
        }
        if(!StringUtils.isEmpty(param.getDiagonalSizeTolerance())){
            lambda.eq(SpecsConfig::getDiagonalSizeTolerance, param.getDiagonalSizeTolerance());
        }
        if(!StringUtils.isEmpty(param.getRemark())){
            lambda.eq(SpecsConfig::getRemark, param.getRemark());
        }
        lambda.orderBy(true,false, SpecsConfig::getSpecsId);
    }
}
